/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package progettode_co.Test;

/**
 *
 * @author Domenico
 */



import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
  static public void main(String args[]) throws Exception {
      test();
      test();
  }
  static void test() throws FileNotFoundException, IOException { 
      FileInputStream fin = new FileInputStream("infile.txt");
    FileOutputStream fout = new FileOutputStream("outfile.txt");

    FileChannel inc = fin.getChannel();
    FileChannel outc = fout.getChannel();

    ByteBuffer bb = ByteBuffer.allocate(1024);

    while (true) {
      int ret = inc.read(bb);
      if (ret == -1) 
        break;
      bb.flip();
      outc.write(bb);
      bb.clear(); 
    }
  }
}

